package com.example.zyfyptlzx729.model;

import com.example.zyfyptlzx729.bean.VideonewBean;
import com.example.zyfyptlzx729.common.Common;
import com.example.zyfyptlzx729.iface.VideonewListener;
import com.example.zyfyptlzx729.iface.Videonewiface;
import com.example.zyfyptlzx729.service.VideonewService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class VideonewModel implements Videonewiface {
    private Retrofit retrofit;
    public VideonewModel(){
        retrofit=new Retrofit.Builder()
                .baseUrl(Common.BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    @Override
    public void getResultList(String sessionID, String mod, int page, final VideonewListener videonewListener) {
        VideonewService service=retrofit.create(VideonewService.class);
        Call<List<VideonewBean>> call=service.getVideonewList(sessionID,mod,page);
        call.enqueue(new Callback<List<VideonewBean>>() {
            @Override
            public void onResponse(Call<List<VideonewBean>> call, Response<List<VideonewBean>> response) {
                if(response.isSuccessful()&&response!=null){
                    videonewListener.onResponse(response.body());
                }
                else{
                    videonewListener.onFail("on response fail");
                }
            }

            @Override
            public void onFailure(Call<List<VideonewBean>> call, Throwable t) {
                videonewListener.onFail(t.toString());
            }
        });
    }
}
